package logic

import (
	"common/model"
	"common/utils"
	"context"
	"errors"
	user "user_srv/proto"
)

func (u *UserServer) UserLogin(ctx context.Context, req *user.UserLoginRequest) (*user.UserLoginResponse, error) {
	var userInfo model.User
	err := userInfo.GetUserInfoByTel(req.Tel)
	if err != nil {
		return nil, err
	}
	if userInfo.ID == 0 {
		return nil, errors.New("当前用户未注册 请前往注册")
	}
	if userInfo.Passwd != utils.Md5(req.Passwd) {
		return nil, errors.New("密码错误  请重试")
	}
	return &user.UserLoginResponse{UserId: int64(userInfo.ID)}, nil
}
